<template>
  <div class="water-verification-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="1" :tab="`待审核(${pageStat['1']})`"></a-tab-pane>
        <a-tab-pane key="2" :tab="`待核销(${pageStat['2']})`"></a-tab-pane>
        <a-tab-pane key="3" :tab="`已核销(${pageStat['3']})`"></a-tab-pane>
        <a-tab-pane key="0" :tab="`全部(${pageStat['0']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :activeKey="activeKey"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
        :sort-config="{ remote: true }"
        @sort-change="sortChangeHandle"
      >
        <template #tool>
          <a-button type="primary" @click="downloadDataHandle" v-if="['1', '2', '3', '0'].includes(activeKey)">批量导出</a-button>
          <a-button type="primary" @click="batchImportDepsoitHandle" v-if="['1'].includes(activeKey)">批量导入来款</a-button>
          <a-button type="primary" @click="downloaAlldDataHandle" v-if="['1', '2', '3'].includes(activeKey)">导出全部流水</a-button>
          <a-button type="primary" @click="batchChargeOffBillHandle" v-btnAuth="'WATERVERIFICATION_CHARGE_OFF_BILL'" v-if="['2'].includes(activeKey)">核销账单</a-button>
          <a-button type="primary" @click="reverseChargeOffHandle" v-btnAuth="'WATERVERIFICATION_REVERSE_CHARGE_OFF'" v-if="['2', '3'].includes(activeKey)">反核销</a-button>
          <a-button type="primary" @click="verificationRemarkHandle" v-if="['2', '3'].includes(activeKey)">核销备注</a-button>
          <a-button type="primary" @click="reverseApprovalHandle" v-btnAuth="'WATERVERIFICATION_REVERSE_APPROVA'" v-if="['2'].includes(activeKey)">反审核</a-button>
          <a-button @click="showDeleteLogHandle" v-if="activeKey !== '0'">来款删除日志</a-button>
        </template>
        <template #billNum="{ row }">
          {{ row.billNum }}
        </template>
        <template #image="{ row }">
          <a-image :width="80" :src="row.image" />
        </template>
        <template #chargeOffState="{ row }">
          <a-tag v-if="row.chargeOffState === 0" color="#cccc"> 未核销 </a-tag>
          <a-tag v-if="row.chargeOffState === 1" color="#2db7f5"> 部分核销 </a-tag>
          <a-tag v-if="row.chargeOffState === 2" color="#87d068"> 已核销 </a-tag>
        </template>
        <template #action="{ row }">
          <template v-if="activeKey === '1'">
            <a-button type="link" @click="auditDepositHandle(row)" v-btnAuth="'WATERVERIFICATION_AUDIT_DEPOSIT'">审核</a-button>
            <a-button type="link" @click="showLogHandle(row)">日志</a-button>
            <a-button type="link" danger @click="deleteDepositHandle(row)">删除</a-button>
          </template>
          <template v-if="activeKey === '2'">
            <a-button type="link" @click="chargeOffBillHandle(row)" v-btnAuth="'WATERVERIFICATION_CHARGE_OFF_BILL'">核销账单</a-button>
            <a-button type="link" @click="showLogHandle(row)">日志</a-button>
          </template>
          <template v-if="['3', '0'].includes(activeKey)">
            <a-button type="link" @click="showLogHandle(row)">日志</a-button>
          </template>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :maskClosable="false" :closable="true" @close="getData" :width="drawerOpts.width" placement="right">
      <component v-model:visible="drawerOpts.visible" :is="drawerOpts.component" :type="drawerOpts.type" :pass-data="drawerOpts.passData" @submit="drawerSubmitHandle"></component>
    </a-drawer>
    <!-- 弹窗 -->
    <a-modal
      v-model:visible="dialogOpts.visible"
      :maskClosable="false"
      :keyboard="false"
      :closable="['BatchImportDeposit', 'AuditDeposit'].includes(dialogOpts.component)"
      :footer="null"
      :title="dialogOpts.title"
      :width="dialogOpts.width"
    >
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import DeleteLog from "./components/deleteLog/index.vue";
import BatchImportDeposit from "./components/batchImportDepsoit/index.vue";
import AuditDeposit from "./components/auditDeposit/index.vue";
import OperationLog from "./components/operationLog/index.vue";
import VerificationBill from "./components/verificationBill/index.vue";
import VerificationRemark from "./components/verificationRemark/index.vue";
import TableHook from "@/hook/tableHook";
export default {
  name: "WaterVerification",
  components: {
    BatchImportDeposit,
    DeleteLog,
    AuditDeposit,
    OperationLog,
    VerificationBill,
    VerificationRemark
  }
};
</script>
<script lang="ts" setup>
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import { searchItemList } from "./data";
import { onActivated } from "vue";
const { tableHeight, loading } = TableHeightHook(110);
const { tableData, searchForm, drawerOpts, tableRef, dialogOpts, activeKey, pageStat, tableColumn } = InitHook();
const {
  searchHandle,
  chargeOffBillHandle,
  getData,
  showLogHandle,
  reverseApprovalHandle,
  changeTabHandle,
  batchImportDepsoitHandle,
  showDeleteLogHandle,
  auditDepositHandle,
  deleteDepositHandle,
  reverseChargeOffHandle,
  batchChargeOffBillHandle,
  downloadDataHandle,
  downloaAlldDataHandle,
  verificationRemarkHandle
} = OperationHook({
  searchForm,
  tableData,
  drawerOpts,
  loading,
  tableRef,
  dialogOpts,
  activeKey,
  pageStat
});
onActivated(() => {
  searchHandle();
});
const { sortChangeHandle } = TableHook({ searchForm }, getData);
const { drawerSubmitHandle, dialogSubmitHandle } = ModalHook({
  drawerOpts,
  dialogOpts,
  callBack: () => searchHandle()
});
</script>
<style lang="stylus" scoped>
.water-verification-page{
    .emphasis-item {
        color: #fe8100;
        font-weight: 600;
    }
}
</style>
